package com.xu.ai.model.multiplemodels.controller;

import com.xu.ai.model.multiplemodels.prompt.ChatClientPrompt;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.ai.deepseek.DeepSeekChatOptions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.Map;

/**
 * deepseek多模型聊天客户端 controller
 *
 * @author xuguan
 * @since 2025/10/9
 */
@RestController
@RequestMapping("/api/deepseek/multi-model/")
public class DeepseekMultiModelController {
    private final ChatClient deepSeekChatClient;
    private final ChatClient deepSeekReasonerClient;

    public DeepseekMultiModelController(DeepSeekChatModel deepSeekChatModel) {
        this.deepSeekChatClient = ChatClient.builder(deepSeekChatModel)
                .defaultSystem(ChatClientPrompt.DEFAULT_SYSTEM_PROMPT.render(Map.of("modelName", "deepseek")))
                .defaultOptions(DeepSeekChatOptions.builder().model("deepseek-chat").build())
                .build();
        this.deepSeekReasonerClient = ChatClient.builder(deepSeekChatModel)
                .defaultSystem(ChatClientPrompt.DEFAULT_SYSTEM_PROMPT.render(Map.of("modelName", "deepseek")))
                .defaultOptions(DeepSeekChatOptions.builder().model("deepseek-reasoner").build())
                .build();
    }

    @GetMapping(value = "/deepseek-chat", produces = "text/html;charset=UTF-8")
    public Flux<String> deepseekChat() {
        return deepSeekChatClient.prompt()
                .user("给我讲个笑话")
                .stream()
                .content();
    }

    @GetMapping(value = "/deepseek-reasoner", produces = "text/html;charset=UTF-8")
    public Flux<String> deepseekReasoner() {
        return deepSeekReasonerClient.prompt()
                .user("给我讲个笑话")
                .stream()
                .content();
    }
}
